﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm.Middle_540_SingleNonDuplicate
{
    class MainProject
    {
        static void Main(string[] args)
        {
           
            int s = SingleNonDuplicate(new int[] {1, 1, 2 });
            Console.WriteLine(s);

            Console.ReadKey();
        }
        public static int SingleNonDuplicate(int[] nums)
        {
            if (nums.Length == 1) return nums[0];
            int firstIndex = 0;
            int secondIndex = 1;
            for (int i = 0; i < nums.Length; i+=2)
            {
                firstIndex = i;
                secondIndex = i+1;
                if (secondIndex>= nums.Length) return nums[firstIndex];
                if (nums[firstIndex]!= nums[secondIndex])
                {
                    return nums[firstIndex];
                }
            }
            return 0;
        }
    }
}
